package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocCategoryDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.VocCategoryCommand;
import com.cskaoyan.wordmemorize.service.VocCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 类目管理
 */
@RestController
@RequestMapping("admin/voc")
public class VocCategoryController {

    @Autowired
    private VocCategoryService vocCategoryService;

    /**
     * 获取指定的书籍类目
     * @param categoryId  书籍类目id
     * @return
     */
    //@SaAdminCheckPermission("super-admin")
    @GetMapping("category")
    public Result addBookCategory(Long categoryId){
        VocCategoryDTO bookCategory = vocCategoryService.getBookCategory(categoryId);
        return Result.ok(bookCategory);
    }

   // @SaAdminCheckPermission("super-admin")
    @PostMapping("category")
    public Result addBookCategory(@RequestBody VocCategoryCommand command){
        vocCategoryService.addBookCategory(command);
        return Result.ok();
    }

    //@SaAdminCheckPermission("super-admin")
    @PutMapping("category")
    public Result updateBookCategory(@RequestBody VocCategoryCommand command){
        vocCategoryService.updateBookCategory(command);
        return Result.ok();
    }

    //@SaAdminCheckPermission("super-admin")
    @GetMapping("category/list")
    public Result<PageDTO<VocCategoryDTO>> getBookCategories(PageRequest pageQuery){
        PageDTO<VocCategoryDTO> bookCategories = vocCategoryService.getBookCategories(pageQuery);

        return Result.ok(bookCategories);
    }

   // @SaAdminCheckPermission("super-admin")
    @DeleteMapping("category/{categoryId}")
    public Result deleteBookCategory(@PathVariable("categoryId") Long categoryId){
        vocCategoryService.deleteBookCategory(categoryId);
        return Result.ok();
    }

    //@SaAdminCheckPermission("super-admin")
    @DeleteMapping("categories")
    public Result deleteBookCategories(@RequestBody BatchDeleteCommand batchDeleteCommand){
        vocCategoryService.deleteBookCategories(batchDeleteCommand);
        return Result.ok();
    }
}
